package ua.mykola.ds.list;

public class Node
{

    String name;

    Node next;

    public Node()
    {
    }

    public Node(String name)
    {
        this.name = name;
    }

    @Override
    public String toString()
    {
        return "Node [name=" + name + ", next=" + (next == null ? null : next.name) + "]";
    }

    public static String listToString(Node head)
    {
        Node next = head;
        StringBuilder sb = new StringBuilder();
        while (next != null)
        {
            sb.append(next.toString());
            sb.append("\n");
            next = next.next;
        }

        return sb.toString();
    }

}
